package edu.ubb.scrumster.model.repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import edu.ubb.scrumster.model.model.AbstractModel;
import edu.ubb.scrumster.model.model.Estimation;
import edu.ubb.scrumster.model.model.Task;
import edu.ubb.scrumster.model.model.User;

public class EstimationRepository {

	public EstimationRepository() {
	}

	public ArrayList<Estimation> getAllEstimation() {
		ArrayList<Estimation> list = new ArrayList<Estimation>();
		for (AbstractModel d : DatabaseAccess.getInstance().getAll(DatabaseAccess.ESTIMATION)){
			list.add(getEstimationById(((Estimation) d).getId()));
		}
		return list;
	}

	public void addEstimation(Estimation g) {
		DatabaseAccess.getInstance().addData(g);
	}

	public void updateEstimation(Estimation data) {
		DatabaseAccess.getInstance().updateData(data);
	}

	public void deleteEstimation(Estimation data) {
		DatabaseAccess.getInstance().deleteData(data);
	}

	public Estimation getEstimationById(int id) {
		Estimation e=(Estimation)DatabaseAccess.getInstance().getDataById(id, DatabaseAccess.ESTIMATION);
		e.setTask((Task)DatabaseAccess.getInstance().getDataById(e.getTask().getId(), DatabaseAccess.TASK));
		e.setUser((User)DatabaseAccess.getInstance().getDataById(e.getTask().getId(), DatabaseAccess.USER));
		return e;
	}
}
